﻿using App_Clinique.ClassLibrary.DbContext;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App_Clinique.ClassLibrary.Entities
{
    public partial class Medicament
    {
        /****************************************************************************************************
         * Methods - Inser, Update, Delete
         ***************************************************************************************************/
        public static void Create(Medicament medicament)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Medicament.Add(medicament);
                db.SaveChanges();
            }
        }

        public static void Update(Medicament medicament)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Entry(medicament).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Medicament medicament)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Entry(medicament).State = EntityState.Deleted;
                db.SaveChanges();
            }
        }

        /****************************************************************************************************
         * Methods - Select
         ***************************************************************************************************/
        public static Medicament Get(Int64 medicamentID)
        {
            Medicament Obj = null;

            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                Obj = (from m in db.Medicament
                       where m.MedicamentID == medicamentID
                       select m).SingleOrDefault();
            }

            return Obj;
        }

        public static List<Medicament> GetList()
        {
            List<Medicament> objs = null;

            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                objs = (from m in db.Medicament
                        select m).ToList();
            }

            return objs;
        }
    }
}
